//
//  SDP_CellForTopRanking.m
//  DDP_PRO_B
//
//  Created by sp on 16/3/22.
//  Copyright © 2016年 sp. All rights reserved.
//

#import "SDP_CellForTopRanking.h"   // V
#import "SDP_ModelForTopRanking2.h"    //M
#import <SDWebImage/UIImageView+WebCache.h>  //T

#define WIGHT  [UIScreen mainScreen].bounds.size.width
#define HEIGHT  [UIScreen mainScreen].bounds.size.height

@interface SDP_CellForTopRanking ()

@property (nonatomic, retain)UIImageView *imageForTopRanking;
@property (nonatomic, retain)UILabel *titleLablelForTopRanking;
@property (nonatomic, retain)UILabel *videoInfoLableForTopRanking;

/** 时间显示*/
@property (nonatomic, retain)UILabel *labelForIndex;

/** 图片上的暗色图层*/
@property (nonatomic, retain)UIView *viewForImages;


@end




@implementation SDP_CellForTopRanking

/** 初始化 */

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self creatTableViewForSubViews];
        
    }

    return self;
}


/** 创建子控件*/

- (void)creatTableViewForSubViews{


    //背景图片
    self.imageForTopRanking = [[UIImageView alloc]init];
    self.titleLablelForTopRanking = [[UILabel alloc] init];
    self.titleLablelForTopRanking.textAlignment = NSTextAlignmentCenter;
    self.videoInfoLableForTopRanking = [[UILabel alloc] init];
    self.videoInfoLableForTopRanking.textAlignment = NSTextAlignmentCenter;
    
    /** 暗色蒙版层 */
    self.viewForImages = [[UIImageView alloc] init];
    [self.imageForTopRanking addSubview:self.viewForImages];
    self.viewForImages.backgroundColor = [UIColor darkGrayColor];
    self.viewForImages.alpha = 0.3;
    
    
    // 上横线
    
    UILabel *labelForTopLine = [[UILabel alloc] init];
    labelForTopLine.backgroundColor = [UIColor whiteColor];
    labelForTopLine.frame = CGRectMake(WIGHT/2.15, WIGHT/2.4, WIGHT - WIGHT/2.15 *2, WIGHT/600);
    [self.imageForTopRanking addSubview:labelForTopLine];
    
    // 下标
    
    self.labelForIndex = [[UILabel alloc]init];
    self.labelForIndex.frame = CGRectMake(WIGHT/2.15, WIGHT/2.325, WIGHT - WIGHT/2.15 *2, WIGHT/28);
    //self.labelForIndex.backgroundColor = [UIColor orangeColor];
    self.labelForIndex.textColor = [UIColor whiteColor];
    self.labelForIndex.textAlignment = NSTextAlignmentCenter;
    self.labelForIndex.font = [UIFont systemFontOfSize:15];
    [self.imageForTopRanking addSubview:self.labelForIndex];
    
    
    // 下横线
 
    UILabel *labelForBottomLine = [[UILabel alloc] init];
    labelForBottomLine.backgroundColor = [UIColor whiteColor];
    labelForBottomLine.frame = CGRectMake(WIGHT/2.15, WIGHT/2.1, WIGHT - WIGHT/2.15 *2, WIGHT/600);
    [self.imageForTopRanking addSubview:labelForBottomLine];

    // 字体颜色
    self.titleLablelForTopRanking.textColor = [UIColor whiteColor];
    self.videoInfoLableForTopRanking.textColor = [UIColor whiteColor];
    
    
    // 字号
    
    self.titleLablelForTopRanking.font = [UIFont systemFontOfSize:17];
    self.videoInfoLableForTopRanking.font = [UIFont systemFontOfSize:12];
    
    
    [self.contentView addSubview:self.imageForTopRanking];
    [self.imageForTopRanking addSubview:self.titleLablelForTopRanking];
    [self.imageForTopRanking addSubview:self.videoInfoLableForTopRanking];
}




- (void)layoutSubviews{
    
    
    [super layoutSubviews];


    /** 背景图片布局 imageview*/
    self.imageForTopRanking.frame = CGRectMake(0, 0, WIGHT, HEIGHT/3);
    self.viewForImages.frame = CGRectMake(0, 0, WIGHT, HEIGHT/3);

    /** 文本主题布局 label*/
    self.titleLablelForTopRanking.frame  = CGRectMake(WIGHT / 12, WIGHT/4, WIGHT - WIGHT / 12 * 2, WIGHT / 15);

    /** 视频详情信息布局 label */
    self.videoInfoLableForTopRanking.frame  = CGRectMake(WIGHT / 6, WIGHT/3.1, WIGHT - WIGHT / 6 * 2, WIGHT / 20);
    
    


}



- (void)passModelForTopRanking: (SDP_ModelForTopRanking2 *)model {


    // 主题赋值
    self.titleLablelForTopRanking.text = model.title;
    
    // 背景图片
    NSString *urlForInages = [model.cover objectForKey:@"feed"];
    [self.imageForTopRanking sd_setImageWithURL:[NSURL URLWithString:urlForInages] placeholderImage:nil];
    
    // 视频时长和类型
    NSInteger second = [model.duration integerValue];
    NSString *str_minute = [NSString stringWithFormat:@"%02ld",second/60];
    NSString *str_second = [NSString stringWithFormat:@"%02ld",second%60];
    NSString *strForVideoInfo = [NSString stringWithFormat:@"#%@  /  %@' %@''", model.category, str_minute, str_second];

    self.videoInfoLableForTopRanking.text = strForVideoInfo;

    self.labelForIndex.text = [NSString stringWithFormat:@"%@.", model.idx];

}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
